import numpy as np
from sklearn.decomposition import PCA

class PCACompressor:
    def __init__(self, n_components: int):
        self.n_components = n_components
        self.pca = None

    def fit_pca(self, local_matrix: np.ndarray):
        """Fit PCA on the local matrix."""
        self.pca = PCA(n_components=self.n_components)
        self.pca.fit(local_matrix)

    def transform(self, vec: np.ndarray) -> np.ndarray:
        """Transform a vector using the fitted PCA."""
        if self.pca is None:
            raise ValueError("PCA model is not fitted yet.")
        return self.pca.transform(vec.reshape(1, -1))[0]

    def encrypt_and_send(self, vec: np.ndarray) -> np.ndarray:
        """Placeholder for encryption and sending logic."""
        # Replace with actual encryption logic
        return vec + 1